//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.ty.jpa.utils;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

public final class EntityUtils {
    private static final Logger log = LoggerFactory.getLogger(EntityUtils.class);

//    public static <T> List<T> cast(Collection<?> source, Class<T> clazz) {
//        return JSON.parseArray(JSON.toJSONString(source), clazz);
//    }

    public static Map<String, Object> castToMap(Object object) {
        try {
            Map<String, Object> map = new HashMap<>();
            Field[] var2 = object.getClass().getDeclaredFields();
            int var3 = var2.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                Field field = var2[var4];
                boolean flag = field.isAccessible();
                field.setAccessible(true);
                Object o = field.get(object);
                map.put(field.getName(), o);
                field.setAccessible(flag);
            }

            return map;
        } catch (Exception var8) {
            log.error(var8.getMessage(), var8);
            return null;
        }
    }

    public static Map<Field, Object> notNullCastToMap(Object object) {
        try {
            Map<Field, Object> map = new HashMap<>();
            Field[] var2 = object.getClass().getDeclaredFields();
            int var3 = var2.length;
            for(int var4 = 0; var4 < var3; ++var4) {
                Field field = var2[var4];
                boolean flag = field.isAccessible();
                field.setAccessible(true);
                Object o = field.get(object);
                if (o != null) {
                    if (o instanceof String && !StringUtils.hasText((String)o)) {
                        continue;
                    }
                    map.put(field, o);
                }
                field.setAccessible(flag);
            }

            return map;
        } catch (Exception var8) {
            log.error(var8.getMessage(), var8);
            return null;
        }
    }

    private EntityUtils() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }
}
